<?php


namespace App\Models\Attributes;

use App\Services\Locale\Language;
use App\Services\MobileApp\AppEnv;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;

/**
 * 属性（关联分组 / 排序）
 *
 * @property-read  int $attribute_id
 * @property-read AttributeDescription attributeDescription
 *
 * @mixin Builder
 */
class Attribute extends Model
{
    protected $table = 'attribute';
    protected $guarded = [];

    protected $primaryKey = 'attribute_id';

    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function attributeGroupDescription()
    {
        return $this->belongsTo(AttributeGroupDescription::class, 'attribute_group_id', 'attribute_group_id')
            ->where('language_id', AppEnv::languageId());
    }

    public function attributeDescription()
    {
        return $this->belongsTo(AttributeDescription::class, 'attribute_id', 'attribute_id')
            ->where('language_id', AppEnv::languageId());
    }
}
